package cn.liujing.controller;

import cn.liujing.service.OrderService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@DefaultProperties(defaultFallback = "AllError")
public class OrderController {
    @Resource
    private OrderService orderService;
    @RequestMapping("/test/ok/{id}")
    @HystrixCommand(fallbackMethod = "error",commandProperties = {
    @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="3000")
    })
    public String OK(@PathVariable("id")String id){
        return orderService.ok(id);
    }
    public String error(String id){
        return "orderController的的error";
    }
    //用来测试全局服务降级
    @HystrixCommand
    @RequestMapping("/test/all/{id}")
    public String Alltest(@PathVariable("id") String id){
        int num=1/0;
        return orderService.ok(id);
    }
    public String AllError(){
        return "全局的服务降级处理";
    }
}
